package org.example;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @description: 拦截器
 * @author: xukang
 * @create: 2025-05-30
 */
public class MyInterceptor implements ProducerInterceptor {
    @Override
    public ProducerRecord onSend(ProducerRecord producerRecord) {
        // 发送服务时 触发
        System.out.println("发送服务时 触发" + producerRecord.toString());
        return producerRecord;
    }

    @Override
    public void onAcknowledgement(RecordMetadata recordMetadata, Exception e) {
        // 收到服务时触发
        System.out.println("收到服务时触发" + recordMetadata.toString());

    }

    @Override
    public void close() {
        // 关闭链接时触发
    }

    @Override
    public void configure(Map<String, ?> map) {
        // 遍历 配置项
        for (Map.Entry<String, ?> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ":::" + entry.getValue());
        }
    }
}
